﻿using System;
using DataGeneration.Domain.Helpers;

namespace DataGeneration.Domain.CustomProcessors
{
    public static class DateTimeProcessor
    {
        public static string GenerateValue(string entry)
        {
            string returnValue;
            if (entry.Equals("dateofbirth"))
            {
                returnValue = string.Format("'{0}'", RandomMizer.RandomDateOfBirth);
            }
            else if (entry.Equals("dateofdeath"))
            {
                returnValue = string.Format("'{0}'", RandomMizer.RandomDateOfBirth);
            }
            else if (entry.Equals("timestamp"))
            {
                DateTime adate = DateTime.Now;
                returnValue = string.Format("'{0} {1} {2}'", adate.Day, EnumHelper.Convert<Month>(adate.Month.ToString(), true).ToString(), adate.Year);
            }
            else if (entry.Equals("datefirstoffence"))
            {
                DateTime adate = DateTime.Now.AddDays(-7);
                returnValue = string.Format("'{0} {1} {2}'", adate.Day,
                                                            EnumHelper.Convert<Month>(adate.Month.ToString(), true).ToString(),
                                                            adate.Year);
            }
            else if (entry.Equals("today"))
            {
                DateTime adate = DateTime.Now;
                returnValue = string.Format("'{0} {1} {2}'", adate.Day,
                    EnumHelper.Convert<Month>(adate.Month.ToString(), true).ToString(),
                    adate.Year);
            }
            else if (entry.Equals("todayminus"))
            {
                string[] entries = entry.Split("-".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                int maxCharacters;
                if (entries.Length > 1 && int.TryParse(entries[1], out maxCharacters))
                {
                    DateTime adate = DateTime.Now.AddDays(-maxCharacters);
                    returnValue = string.Format("'{0} {1} {2}'", adate.Day,
                                                            EnumHelper.Convert<Month>(adate.Month.ToString(), true).ToString(),
                                                            adate.Year);
                }
                else
                {
                    throw new Exception("The value for the todayminus hint must follow the following pattern todayminus-34 Where the 34 signifies the number of days to subtract from the current date.");
                }
            }
            else if (entry.Equals("todayplus"))
            {
                string[] entries = entry.Split("-".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                int maxCharacters;
                if (entries.Length > 1 && int.TryParse(entries[1], out maxCharacters))
                {
                    DateTime adate = DateTime.Now.AddDays(maxCharacters);
                    returnValue = string.Format("'{0} {1} {2}'", adate.Day,
                                                            EnumHelper.Convert<Month>(adate.Month.ToString(), true).ToString(),
                                                            adate.Year);
                }
                else
                {
                    throw new Exception("The value for the todayplus hint must follow the following pattern todayplus-34 Where the 34 signifies the number of days to add to the current date.");
                }
            }
            else
            {
                returnValue = string.Format("'{0}'", RandomMizer.RandomDateString);
            }

            return returnValue;
        }
    }
}